/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ecommerce.dao;

import ecommerce.model.CreditCard;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Hadi
 */
@Repository
public class CreditCardDao {

    @Autowired private SessionFactory sessionFactory;

    public void save(CreditCard cc){
        sessionFactory.getCurrentSession().saveOrUpdate(cc);
    }

    public void delete(CreditCard cc){
        sessionFactory.getCurrentSession().delete(cc);
    }

    public CreditCard findById(Long id){
        return (CreditCard) sessionFactory.getCurrentSession().get(CreditCard.class, id);
    }

    public List<CreditCard> getAll(){
        return sessionFactory.getCurrentSession().createQuery("from CreditCard").list();
    }
}
